<template>
  <div class="email-config-container">
    <BasicForm @submit="handleSubmit" @register="registerForm">
      <template #coverUrlSlot="{ model, field }">
        <Spin :spinning="spinning">
          <Upload
            v-model:file-list="fileList"
            name="file"
            list-type="picture-card"
            :show-upload-list="false"
            :action="uploadImgApi"
            :before-upload="beforeUpload"
            @change="handleChange"
          >
            <img v-if="model[field]" :src="model[field]" alt="avatar" />
            <div v-else>
              <div class="ant-upload-text">点击上传</div>
            </div>
          </Upload>
        </Spin>
        <div class="hint">建议图片尺寸：宽750*高440rpx</div>
      </template>
      <template #fieldUrlSlot="{ model, field }">
        <Spin :spinning="spinning">
          <Upload
            v-model:file-list="fileList"
            name="file"
            list-type="picture-card"
            :show-upload-list="false"
            :action="uploadImgApi"
            :before-upload="beforeUpload"
            @change="handleChange"
          >
            <img v-if="model[field]" :src="model[field]" alt="avatar" />
            <div v-else>
              <div class="ant-upload-text">点击上传</div>
            </div>
          </Upload>
        </Spin>
        <div class="hint">建议图片尺寸：宽750*高440rpx</div>
      </template>
    </BasicForm>
    <a-button type="primary" class="save">保存</a-button>
  </div>
</template>

<script lang="ts">
  import { defineComponent, ref } from 'vue';
  import { serviceManualSchemas } from './serviceManual.data';
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { Spin, Upload } from 'ant-design-vue';

  export default defineComponent({
    name: 'EmailConfig',
    components: {
      BasicForm,
      Spin,
      Upload,
    },
    setup() {
      const spinning = ref(false);
      const fileList = ref<any[]>([]);
      const uploadImgApi = () => {};

      const [registerForm, { setFieldsValue, validate, validateFields }] = useForm({
        labelWidth: 200,
        schemas: serviceManualSchemas,
        showActionButtonGroup: false,
        wrapperCol: {
          span: 14,
        },
      });
      function handleSubmit() {}

      // 上传前
      const beforeUpload = () => {
        console.log('beforeUpload');
      };

      const handleChange = () => {
        console.log('handleChange');
      };

      return {
        handleSubmit,
        registerForm,
        spinning,
        fileList,
        uploadImgApi,
        beforeUpload,
        handleChange,
      };
    },
  });
</script>
<style lang="less" scoped>
  .email-config-container {
    background-color: #fff;
    width: 100%;
    height: 100%;
    padding: 100px 0;
    .save {
      margin-top: 30px;
      margin-left: 200px;
    }
  }
</style>
